using System.Web.UI;
using Microsoft.SharePoint.WebPartPages;
using System.IO;
using Microsoft.SharePoint.WebControls;
using System.Web;

namespace Macaw.Wss3.LookupFieldControlAdapter
{
    public class LookupFieldControlAdapter : System.Web.UI.Adapters.ControlAdapter
    {
        public LookupField FieldControl
        {
            get
            {
                return this.Control as LookupField;
            }
        }

        protected override void CreateChildControls()
        {
            if (FieldControl == null)
            {
                base.CreateChildControls();
                return;
            }

            if (FieldControl.ControlMode != SPControlMode.Display)
            {
                HttpCookie cookie = HttpContext.Current.Request.Cookies["WSS_AccessibilityFeature"];
                if (cookie == null)
                {
                    try
                    {
                        HttpCookie tempcookie = new HttpCookie("WSS_AccessibilityFeature");
                        tempcookie.Value = "true";
                        HttpContext.Current.Request.Cookies.Add(tempcookie);
                        base.CreateChildControls();
                    }
                    finally
                    {
                        HttpContext.Current.Request.Cookies.Remove("WSS_AccessibilityFeature");
                    }
                }
                else if (cookie.Value == "false")
                {
                    try
                    {
                        cookie.Value = "true";
                        base.CreateChildControls();
                    }
                    finally
                    {
                        cookie.Value = "false";
                    }
                }
                else
                {
                    base.CreateChildControls();
                }
            }
            else
            {
                base.CreateChildControls();
            }
        }
    }
}